package com.srs.backend.pojo;


import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.List;

@Data
@NoArgsConstructor
@AllArgsConstructor
public class Server {
    @TableId(type = IdType.AUTO)
    private Integer id;
    private String name;
    private String sex;
    private String phone;
    private String remark;
    private Integer uid;

    private transient Double serverReviewStar;

    public Server(Integer id, String name, String sex, String phone, String remark, Integer uid) {
        this.id = id;
        this.name = name;
        this.sex = sex;
        this.phone = phone;
        this.remark = remark;
        this.uid = uid;

    }
    public void calculateServerReviewStar(List<Integer> reviewList) {
        if (reviewList != null && !reviewList.isEmpty()) {
            Double sum = 0.0;
            for (int review : reviewList) {
                sum += review;
            }
            Double average = sum / reviewList.size();
            this.serverReviewStar = average;
        }
    }
//    @Data 会自动注入get、set函数，不需要写
//    // 获取 serverReviewStar 的方法
//    public String getServerReviewStar() {
//        return serverReviewStar;
//    }
}

